<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue组件生命周期</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
    <div id="Application">
        <sub-com v-if="show">
            {{content}}
        </sub-com>
        <button @click="changeShow">测试</button>
    </div>
    <script>
        const sub = {
            beforeCreate () {
                console.log("组件即将创建前")
            },
            created () {
                console.log("组件创建完成")
            },
            beforeMount () {
                console.log("组件被即将挂载前")
            },
            mounted () {
                console.log("组件挂载完成")
            },
            beforeUpdate () {
                console.log("组件即将更新前")
            },
            updated () {
                console.log("组件更新完成")
            },
            activated () {
                console.log("被缓存的组件激活时调用")
            },
            deactivated () {
                console.log("被缓存的组件停用时调用")
            },
            beforeUnmount() {
                console.log("组件即将被卸载前调用")
            },
            unmounted() {
                console.log("组件被卸载后调用")
            },
            errorCaptured(error, instance, info) {
                console.log("捕获到来自子组件的异常时调用")
            },
            renderTracked(event) {
                console.log("虚拟DOM重新渲染时调用")
            },
            renderTriggered(event) {
                console.log("虚拟DOM被触发渲染时调用")
            },
            template:`
                <div>
                    <slot></slot>
                </div>
            `
        }
        const App = Vue.createApp({
            data(){
                return {
                    show:true,
                    content:0
                }
            },
            methods: {
                changeShow(){
                    // this.show = !this.show
                    this.content += 1
                }
            }
        })
        App.component("sub-com", sub)
        App.mount("#Application") 
    </script>
</body>
</html>